﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKArchUtils.ColumnProfileAnalyze;

namespace YJKRevitStructModel.Data
{
	public class ColumnDataPack : ElementDataPack
	{
		public ColumnDataPack(Autodesk.Revit.DB.Document Doc, ElementId LinkInstanceId, ElementId elementId, Transform LinkDocTransForm, ExternalCommandData cmdData) : base(Doc, LinkInstanceId, elementId, LinkDocTransForm, cmdData)
		{
			ElementId typeId = this.m_doc.GetElement(this.m_elementId).GetTypeId();
			FamilySymbol familySymbol = this.m_doc.GetElement(typeId) as FamilySymbol;
			base.StrTypeName = familySymbol.Name;
		}

		public new bool GetZFaceLoop(out List<Curve> lstCrv)
		{
			lstCrv = new List<Curve>();
			Element element = this.m_doc.GetElement(this.m_elementId);
			ColumnProfileAnalyzer columnProfileAnalyzer = new ColumnProfileAnalyzer(this.m_cmdData);
			List<ColumnProfileInfo> list = new List<ColumnProfileInfo>();
			columnProfileAnalyzer.GetColumnProfile(element, ref list);
			foreach (ColumnProfileInfo columnProfileInfo in list)
			{
				List<XYZ> loop = columnProfileInfo.Loop;
				List<XYZ> list2 = new List<XYZ>();
				foreach (XYZ xyz in loop)
				{
					XYZ newPt = this.m_LinkDocTransForm.OfPoint(xyz);
					if (list2.FindIndex((XYZ e) => e.IsAlmostEqualTo(newPt)) == -1)
					{
						list2.Add(newPt);
					}
				}
				for (int i = 0; i < list2.Count; i++)
				{
					int index = (i + 1) % list2.Count;
					Curve curve = Line.CreateBound(list2.ElementAt(i), list2.ElementAt(index));
					lstCrv.Add(curve);
					base.ArCrvEdage.Append(curve);
				}
			}
			return false;
		}

		public LinkDocPacker m_LinkDocPacker;
	}
}
